﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using StockInfoFacade.Utils;
using StockInfoLoader.Utils;

namespace TST_ALL
{
    [TestClass]
    public class TST_ThreadWorker
    {

        [TestMethod]
        public void TST_ProducerConsumer()
        {

            StringBuilder sbThreaOut = new StringBuilder();

            PCQueue Suspect = new PCQueue(3);

            Action pMethod1 = new Action( () =>
            {
                sbThreaOut.Append(string.Format("consumer {0}", 1));    
                return;    

            });
            Action pMethod2 = new Action( () =>
            {
                sbThreaOut.Append(string.Format("consumer {0}", 2));    
                return;    

            });
            Action pMethod3 = new Action( () =>
            {
                sbThreaOut.Append(string.Format("consumer {0}", 3));    
                return;    

            });


            Suspect.EnqueueItem(pMethod1);
            Suspect.EnqueueItem(pMethod2);
            Suspect.EnqueueItem(pMethod3);

            Suspect.EnqueueItem(pMethod1);
            Suspect.EnqueueItem(pMethod2);

            Suspect.WaitTillEmptyQueue();
            Assert.AreEqual("consumer 1consumer 2consumer 3consumer 1consumer 2".Length, sbThreaOut.ToString().Length);
        }
    }
}
